﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using SERP.StringMappings;
using SERP.DAO;
using SERP.Controllers;
namespace SERP.Modules.Menus{
	public partial class MenusViewInfo : SERP.Modules.ModuleBase
	{
		private MenusController controller = new MenusController();
		public MenusController Controller{
			get{
				return controller;
			} 
		}
		protected void Page_Load(object sender, EventArgs e){
    		LoadLanguage();	
			if(!this.IsPostBack){		
				BindInfo();	
			}
		}
		//Load All lable text
		private void LoadLanguage(){
			labelMenuName.Text=MenusStringMapping.MenuName+":";
			labelDescription.Text=MenusStringMapping.Description+":";
			labelIconName.Text=MenusStringMapping.IconName+":";
			labelMenuUrl.Text=MenusStringMapping.MenuUrl+":";
			labelParentId.Text=MenusStringMapping.ParentId+":";
			labelModuleId.Text=MenusStringMapping.ModuleId+":";
		}
		public MenusEntity GetObject(){
			controller.LoadObject(Int32.Parse(Request["MenuId"]));
			return controller.MenusObject;
		}
		private void BindInfo(){
			MenusEntity o=GetObject();		
			CopyToSreen(o);
			BindParentId(o);
			BindModuleId(o);
		}
		private void BindParentId(MenusEntity o){
			MenusController ctrlMenus = new MenusController();
			ctrlMenus.LoadObject(o.ParentId);
			MenusEntity oMenus=ctrlMenus.MenusObject;
			if(oMenus!=null){
				txtParentId.Text = oMenus.MenuName.ToString();
			}
			else{
				txtParentId.Text = "";
			}
		}
		private void BindModuleId(MenusEntity o){
			ModulesController ctrlModules = new ModulesController();
			ctrlModules.LoadObject(o.ModuleId);
			ModulesEntity oModules=ctrlModules.ModulesObject;
			if(oModules!=null){
				txtModuleId.Text = oModules.ModuleName.ToString();
			}
			else{
				txtModuleId.Text = "";
			}
		}
		private void CopyToSreen(MenusEntity o){
			txtMenuName.Text=o.MenuName;
			txtDescription.Text=o.Description;
			txtIconName.Text=o.IconName;
			txtMenuUrl.Text=o.MenuUrl;
		}   
}
}
